<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <!-- metas -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="<?=BASEURL.CSS_DIR?>style_edit.css" media="screen"/>
    <link rel="stylesheet" type="text/css" href="<?=BASEURL.CSS_DIR?>popin.css" media="screen"/>
    <!-- javascript -->
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>jquery.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>jquery_std.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>common.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>popin.js" ></script>
    <script type="text/javascript" src="<?=BASEURL.JS_DIR?>toolbar.js" ></script>
    <script type="text/javascript">
    
    //data from server
    myData = {};
    myData.baseUrl  = "<?=site_url('');?>";
    myData.isLogged = <?=$isLogged+0?>;
    myData.pageName = "<?=$pagename?>";
    
    function normalize_str(raw)
    {
        var search_str  = " .ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ";
        var replace_str = "__aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyyby";
        var norm=raw.toLowerCase();
        for (var i=0;i<search_str.length;i++) {
            norm = norm.replace(search_str.charAt(i),replace_str.charAt(i),"g");
        }
        norm = norm.replace(/[^a-zA-Z0-9-_]/, "");
        return norm;
    }
    
    function site_url(url)
    {
        return myData.baseUrl+url; 
    }

    function onResize()
    {
        size=$.windowSize();
        $("#textarea1").height(size.h-170+"px");       
    }

    function btLinks() {
        popIn(400,230,site_url('/admin/wikimgr/createlink'),"create a new link");
    }
    
    function btMedia() {
        popIn(610,450,site_url('/admin/mediamgr/'),"media manager");
    }
   
    $(document).ready(function() {
       
       thisForm=document.myForm;
       $(window).resize(onResize);
       onResize();
       
       //buttons & selects
       
       $("#btLogout").click(function(){
            logout(site_url('/wiki/read/<?=$pagename;?>')); 
       });
       
       $('#btHelp').click( function(){
            popIn(400,500,site_url('/wiki/readpart/help'),'HELP');
       });
       
       $('#btCreatePage').click( function(){
               var nompage = normalize_str(prompt("nom de la nouvelle page"));
               if (nompage != null) 
                   window.location.href=site_url('/admin/wikimgr/edit/'+nompage);
                   
       });
       
       $('#btDeletePage').click( function(){
              if (confirm ("are you sure ?"))
                  window.location.href=site_url('/admin/wikimgr/delete/'+myData.pageName);
       });

       
       $('#selectLangue').change(function(){ 
            switchLang(this.options[this.selectedIndex].value,myData.baseUrl);  
       });
       
       $('#selectVersion').change(function(){ 
            window.location.href=site_url('/admin/wikimgr/edit/'+this.options[this.selectedIndex].value);  
       });
       
       $('#selectPage').change(function(){ 
            window.location.href=this.options[this.selectedIndex].value;  
       });
       
       $("#textarea1").toolbar({buttons: [
        {name:'italic',desc:'mettre en italique',lft:'::',rgt:'::' },
        {name:'bold',desc:'mettre en italique',lft:'**',rgt:'**' },
        {name:'underline',desc:'mettre en italique',lft:'__',rgt:'__' },
        {name:'separ'},
        {name:'h1',desc:'titre',lft:'\\n!',rgt:'' },
        {name:'h2',desc:'sous-titre',lft:'\\n!!',rgt:'' },
        {name:'h3',desc:'sous-titre 2',lft:'\\n!!!',rgt:'' },
        {name:'separ'},
        {name:'link',desc:'make a link',fn:'btLinks' },
        {name:'media',desc:'add a media file',fn:'btMedia' }
         ],
         buttonClass: 'button',
         mainClass: 'toolbar',
         separ: 3
       });
     
    });
    
    </script>
    <title>Nimwiki :: editing :: <?=$pagename?></title>
  </head>
  <body>
<div id="page" >
    <div id="top">
        <span style="float:right;padding-top:11px;" >
            <a href="#" id="btLogout">logout</a>
        </span>
        <span id="logo">
            <img src="<?=BASEURL.IMG_DIR?>logo.gif" />
        </span>
        <span id="titre">
            Editing page : <?=$pagename;?>
        </span> 
    </div><!-- end div top -->
    
    <div id="barre1" >
        <div>
            Languages<br />
            <select id="selectLangue" name="selectLangue">
                <?foreach ($this->i18n->getAllLang() as $lang => $code):?>
                <option value ="<?=$code?> "
                <?if($code==$this->i18n->getLangCode()) echo "selected";?> >
                <?=$lang?>
                </option>
                <?endforeach;?>
            </select>
        </div>
        <div>
            Page<br />
            <select id="selectPage" name="selectPage">
                <?foreach ($this->wiki_model->getAllPages() as $page):?>
                <option value ="<?=$page?> "
                <?if($page==$basepagename) echo "selected";?> >
                <?=$page?>
                </option>
                <?endforeach;?>
            </select>
        </div>
        <div>
            Versions<br />
            <select id="selectVersion" >
                <?foreach($versions as $version):?>
                <option value ="<?=$version["name"]?> "
                <?if($version["name"]==$pagename) echo "selected";?> >
                <?=$version["date"]?>
                </option>
                <?endforeach;?>
            </select>
        </div>
        <div>
            Actions<br />
            <div>
                <a href="#" id="btCreatePage" class="bouton" >New page</a>
                <? if ($this->user->isAuthorized("delete", $pagename)): ?>
                <a href="#" id="btDeletePage" class="bouton" >Delete this page</a>
                <? endif; ?>
                <a href="#" id="btHelp" class="bouton" >Help</a>
            </div>
        </div>
        <div style="float:right"><br />
            <a href="javascript:document.myForm.submit();" class="bouton" >Save</a>
            <a href="<?=site_url('/wiki/read/'.$pagename)?>" class="bouton" >Cancel</a>
        </div>
    </div><!-- end div barre1 -->
    
    <div id="edit">
        <form name="myForm" method="post" action="<?=site_url("/admin/wikimgr/save/$pagename")?>">
        <textarea name="content" id="textarea1" ><?=$content?></textarea><div id="footer" ><!--last modified -->
        <input type="hidden" name="meta[lastauthor]" value="<?=$this->wiki_model->readMeta($pagename,"author")?>" />
        template:
            <select id="selectTemplate" name="meta[template]" >
                <?foreach($templates as $templateKey=>$template):?>
                <option value ="<?=$templateKey?>" <?if($templateKey==getmeta($pagename,'template')) echo "selected";?> >
                    <?=$template[0]?>
                </option>
                <?endforeach;?>
            </select>
        tags:
        <input type="text" name="meta[tags]" value="<?=$this->wiki_model->readMeta($pagename,"tags")?>" />
        </div>
        </form> 
        
    </div> 
</div>
</body>
</html>
